package com.zytlifeservice.config;

import com.github.wxpay.sdk.WXPayConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.*;

/**
 * Created by MJS on 2017/6/21.
 */
@Component
public class WxConfig implements WXPayConfig {

    Logger logger = LoggerFactory.getLogger(WxConfig.class);

    private byte[] certData;

    private String certPath;
    public WxConfig() {

    }

    @Value("${web.cert-path}")
    private void setCertPath(String certPath) {
        this.certPath = certPath;
        try {
            logger.error("cert Path ={}", certPath);
            File file = new File(certPath);
            InputStream certStream = new FileInputStream(file);
            this.certData = new byte[(int) file.length()];
            certStream.read(this.certData);
            certStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getAppID() {
        return "wx8a01d865b0c88467";
    }

    @Override
    public String getMchID() {
        return "1363018602";
    }

    @Override
    public String getKey() {
        return "gaopintech0826hss0402slsdaydayup";
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
